﻿@model MaintenanceModel
@using Nop.Core.Domain.XJ

@{
    //page title
    ViewBag.Title = "查看报修记录";
    //active menu item (system name)
    string page = ViewBag.formPage;
    Html.SetActiveMenuItemSystemName("Maintenance " + page);
}

@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "maintenance-form" }))
{
    @Html.AntiForgeryToken()
    <div class="content-header clearfix">
        <h1 class="pull-left">
            查看报修记录
            <small><i class="fa fa-arrow-circle-left"></i>@Html.ActionLink("返回列表", page)</small>
        </h1>
        <div class="pull-right">
            @{if (Model.CanConfirm)
                {
                    <a class="btn bg-blue" @(Model.State != (int)MaintenanceStateEnum.待确认 ? " disabled" : "") href="javascript: OpenWindow('@(Url.Action("AddConfirmPopup", "Maintenance", new {maintenanceId = Model.Id, btnId = "btnRefreshAllcates", formId = "maintenance-form"}))', 600, 400, true);">
                        <i class="fa fa-comment"></i>
                        确认
                    </a>
                }
            }
            @{if (Model.CanAssign)
                {
                    <a class="btn bg-blue" @(Model.State != (int)MaintenanceStateEnum.待指派 ? " disabled" : "") href="javascript: OpenWindow('@(Url.Action("AddAssignPopup", "Maintenance", new {maintenanceId = Model.Id, btnId = "btnRefreshAllcates", formId = "maintenance-form"}))', 600, 400, true);">
                        <i class="fa fa-comment"></i>
                        指派
                    </a>
                }
            }
            @{if (Model.CanAllocate)
                {
                    <a class="btn bg-blue" @(Model.State != (int)MaintenanceStateEnum.待分配 ? " disabled" : "") href="javascript: OpenWindow('@(Url.Action("AddAllocatePopup", "Maintenance", new {maintenanceId = Model.Id, btnId = "btnRefreshAllcates", formId = "maintenance-form"}))', 600, 400, true);">
                        <i class="fa fa-comment"></i>
                        分配
                    </a>
                }
            }
            @{if (Model.CanComplete)
                {
                    <a class="btn bg-blue" @(Model.State != (int)MaintenanceStateEnum.待维修 ? " disabled" : "") href="javascript: complete(@Model.Id);">
                        <i class="fa fa-star"></i>
                        完工
                    </a>
                }
            }
            @{if (Model.CanComment)
                {
                    <a class="btn bg-blue" @(Model.State != (int)MaintenanceStateEnum.待评价 ? " disabled" : "") href="javascript: OpenWindow('@(Url.Action("AddCommentPopup", "Maintenance", new {maintenanceId = Model.Id, btnId = "btnRefreshComments", formId = "maintenance-form"}))', 600, 400, true);">
                        <i class="fa fa-comment"></i>
                        评论
                    </a>
                }
            }
        </div>
    </div>
    <div id="window" style="display:none;">
        <p>Hello, get started with the Kendo UI for jQuery Window!</p>
    </div>
    <input type="submit" id="btnRefreshAllcates" style="display: none" />
    <script type="text/javascript">

        function complete(id) {
                    if (confirm('@T("Admin.Common.AreYouSure")')) {
                        var postData = {
                            id
                        };
                        addAntiForgeryToken(postData);

                        $.ajax({
                            cache: false,
                            type: 'POST',
                            url: '@Url.Action("Complete", "Maintenance")',
                            data: postData,
                            dataType: 'json',
                            success: function (data) {
                                if (data.result) {
                                    location.reload();
                                }
                                else {
                                    alert(data.msg);
                                }
                                return false;
                            },
                            error: function(xhr, ajaxOptions, thrownError) {
                                alert('Failed to delete');
                            }
                        });
                    }
        }
        $('#btnRefreshAllcates').click(function () {
            //refresh grid
            //var grid = $("#activitylog-grid").data('kendoGrid');
            //grid.dataSource.read();
            location.reload();

            //return false to don't reload a page
            return false;
        });

    </script>
    @Html.Partial("_View", Model)
}
